<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="demo">
    性：<input type="text" placeholder="FirstName" v-model="firstName"><br>
    名：<input type="text" placeholder="LastName" v-model="lastName"><br>
    姓名1(单向): <input type="text" placeholder="Full Name" v-model="fullName"><br>
    姓名2(单向): <input type="text" placeholder="Full Name2" v-model="fullName2"><br>
    姓名3(双向): <input type="text" placeholder="Full Name3" v-model="fullName3"><br>
    <p>人的详细信息{{info}}</p>
  </div>
  <script type="text/javascript" src="../js/vue.js"></script>
  <script>
   const vm= new Vue({
      el:'#demo',
      data(){
        return{
          firstName:'A',
          lastName:'B',
         // fullName:'A-B'
         fullName2:'',
         info:""
        }
      },
      computed:{
        // info(){
        //  setTimeout(()=>{
        //     return `我的姓名为+${this.firstName}${this.lastName}以及其他信息`
        //  },1000)
        // },
        fullName(){
          return this.firstName+'-'+this.lastName
        },
        fullName3:{
          get(){
            return this.firstName+'-'+this.lastName
          },
          set(value){
            const names=value.split("-");
            this.firstName=names[0];
            this.lastName=names[1]
          }
        }
      },
      watch:{
        // firstName(value){
        //    this.fullName2=value+'-'+this.lastName
        //    setTimeout(()=>{
        //     const info= `我的姓名为+${this.firstName}-${this.lastName}以及其他信息`
        //     this.info=info
        //   },1000)
        // },
        firstName:{
          handler(value){
            this.fullName2=value+'-'+this.lastName
           setTimeout(()=>{
            const info= `我的姓名为+${this.firstName}-${this.lastName}以及其他信息`
            this.info=info
          },1000)
          },
          immediate:true,

        }
      }
    })
    vm.$watch('lastName',function(value){
      this.fullName2=value+'-'+this.firstName
    })
  </script>
</body>
</html>